/**
 * 
 */
package switchviz.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import switchviz.Application;


/**
 * @author Thomas
 *
 */
public class MenuPanel extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	private MainPanel _mainPanel = null;
	
	/**
	 * This is the default constructor
	 */
	public MenuPanel(MainPanel mainPanel)
	{
		super();
	
		_mainPanel = mainPanel;
		
		initialize();
	}
	
	public void add(String identifier, JButton button, JPanel panel)
	{
		button.setActionCommand(identifier);
		button.addActionListener(this);
		
		_mainPanel.getCenterPanel().add(panel, identifier);
		add(button);
	}
	
	public void actionPerformed(ActionEvent event)
	{
		if (_mainPanel != null)
		{
			_mainPanel.getCenterPanel().getCardLayout().show(_mainPanel.getCenterPanel(), event.getActionCommand());
			Application.getInstance().getMainFrame().getMainPanel().getStatusBar().setText(event.getActionCommand());
		}
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize()
	{
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	}

}
